package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.DamageDao;
import com.atguigu.jxc.entity.DamageList;
import com.atguigu.jxc.entity.DamageListGoods;
import com.atguigu.jxc.entity.Goods;
import com.atguigu.jxc.service.DamageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author nzmxfan
 * @create 2021-09-04-23:51
 */
@Service
public class DamageServiceImpl implements DamageService {

    @Autowired
    DamageDao damageDao;


    @Override
    public void saveDamage(DamageList damageList, String damageListGoodsStr) {
        // damageListGoodsStr 是报损商品得信息的 json 字符串

        // 设置时间
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        String dateStr = format.format(new Date());
        damageList.setDamageDate(dateStr);
        // 将报损单信息写入数据库
        damageDao.saveDamage(damageList);
    }

    @Override
    public Map<String, Object> getDamageList(String sTime, String eTime) {

        Map<String, Object> map = new HashMap<>();
        List<DamageList> list = damageDao.getDamageList(sTime, eTime);
        map.put("rows", list);
        return map;
    }

    @Override
    public Map<String, Object> goodsList(Integer damageListId) {


        Map<String, Object> map = new HashMap<>();
        List<DamageListGoods> goodsList = damageDao.goodsList(damageListId);
        map.put("rows", goodsList);
        return map;

    }
}
